package easy;

/**
 * 二叉树
 */
public class test5 {
    public static void main(String[] args) {
        test5 test5 = new test5();
        TreeNode t1Node2 = new TreeNode(2);
        TreeNode t1Node3 = new TreeNode(1);
        TreeNode t1Node1 = new TreeNode(1, t1Node2, t1Node3);

        TreeNode t2Node2 = new TreeNode(1);
        TreeNode t2Node3 = new TreeNode(2);
        TreeNode t2Node1 = new TreeNode(1, t2Node2, t2Node3);
        System.out.println(test5.isSameTree(t1Node1, t2Node1));
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        } else if (p.val != q.val) {
            return false;
        } else {
            return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}





